//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
//

#include "BoundaryList.h"
#include <InitStages.h>
#include "lbr/Split.h"
#include <string>
#include <sstream>

Define_Module(BoundaryList);

using namespace std;

int BoundaryList::numInitStages() const
{
    return MAX_STAGE_OVERLAY;
}

void BoundaryList::initialize(int stage)
{
	if (stage != MIN_STAGE_OVERLAY)
		return;
	WATCH_VECTOR(b);
}

void BoundaryList::initializeList(string& boundaries, const NodeHandle& owner){
    this->owner = owner;
    b.clear();
	// parse boundaries
	parseBoundaries(boundaries);
}

void BoundaryList::parseBoundaries(string &boundaries)
{
	istringstream sin(boundaries);
	// {0,50,0}{1,40,0},...
	char lp, rp, co;
	int dim, dir;
	double coord;
	for(int i=0;sin.peek()!=EOF;i++){
		sin >> lp >> dim >> co >> coord >> co >> dir >> rp;
		Split *split = new Split(coord, static_cast<Dim>(dim), static_cast<Side>(dir));
		b.push_back(*split);
	}
}

//void BoundaryList::initializeBoundaryList(const BoundaryList & boundaries)
//{
//	copy(boundaries._b.begin(), boundaries._b.end(), this->_b.begin());
//}


